package com.ruoyi.project.cms.warehouse.service.impl;

import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.cms.warehouse.domain.CmsStockGoods;
import com.ruoyi.project.cms.warehouse.mapper.CmsStockGoodsMapper;
import com.ruoyi.project.cms.warehouse.service.IGoodsService;
import com.ruoyi.project.system.role.domain.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Autowired
    private CmsStockGoodsMapper cmsStockGoodsMapper;

    @Override
    public List<CmsStockGoods> selectAll(CmsStockGoods goods) {
        return cmsStockGoodsMapper.selectAll(goods);
    }

    @Override
    public String findByName(String name) {
        CmsStockGoods cmsStockGoods = cmsStockGoodsMapper.selectByName(name);
        if (cmsStockGoods !=null ){
            return "1";
        }
        return "0";
    }

    @Override
    public String finByProductCode(String productCode) {
        CmsStockGoods cmsStockGoods = cmsStockGoodsMapper.selectByProductCode(productCode);
        if (cmsStockGoods!=null){
            return "1";
        }
        return "0";
    }

    @Override
    public CmsStockGoods findByProductCode(String productCode) {
        return cmsStockGoodsMapper.selectByProductCode(productCode);
    }

    @Override
    public int addGoods(CmsStockGoods goods) {
        return cmsStockGoodsMapper.addGoods(goods);
    }

    @Override
    public int updateGoods(CmsStockGoods goods) {
        return cmsStockGoodsMapper.updateGoods(goods);
    }

    @Override
    public int deleteByids(String ids){
        Long[] goodsId = Convert.toLongArray(ids);
        return cmsStockGoodsMapper.deleteByids(goodsId);
    }
}
